package com.modemMgr.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.modemMgr.util.DBAccessor;
import com.modemMgr.vo.Item;

public class ItemDAO extends BaseDAO{
	public ItemDAO(DBAccessor dbAccessor) {
		super(dbAccessor);
	}

	public List<Item> getAllItems() throws Exception
	{
		String sql = "select * from items";
		return dbAccessor.queryList(Item.class, sql);
	}
	
	public Map<Integer, String> getItemsMap() throws Exception
	{
		List<Item> list = getAllItems();
		Map<Integer, String> map = new HashMap<Integer, String>();
		
		for (Item item : list)
		{
			map.put(item.getItem_id(), item.getItem_name());
		}
		return map;
	}
	
	public List<Item> getItemsByItemTypeId(int itemTypeId) throws Exception
	{
		String sql = "select * from items where item_type_id = ?";
		List<Item> list = dbAccessor.queryList(Item.class, sql, new Object[]{itemTypeId});
		return list;
	}
}
